function goaddtaskmodelhtml(){
    $("#addtaskname").val("");
    $("#addcallnumber").val("");
    $("#addruncycle").val("");
    $("#addtaskid").val(-1);
    $("#checkcasetaskid input").each(function (){
            $(this).attr("checked",false);
            $(this).prop('checked',false)
        }
    )
    $("#addruntaskmodel").modal('show')
}

function addtaskhtml(){
    var taskparam=gathttptaskparam();
    $.ajax({
        type:"post",
        url:"/api/task/addtask",
        contentType: 'application/json',
        data:JSON.stringify(taskparam),
        success:function (data){
            addupdatainfo(data);
        }
    })
}

function gettaskheml(taskid){
    $.get("/api/task/gettask",{
        taskid:taskid
    },function (data){
        settaskhtml(data)
    })
}

function settaskhtml(data){
    goaddtaskmodelhtml();
    $("#addtaskname").val(data.taskname);
    $("#addcallnumber").val(data.callnumber);
    $("#addruncycle").val(data.runcycle);
    $("#addtaskid").html(data.id);
    $("#addruntaskmodel").modal('show');
    var caseisinfo=data.caseinfo;
    if(caseisinfo.length<1){
        return;
    }
    var casearrays=caseisinfo.split(",");
    for(var i=0;i<casearrays.length;i++){
        console.log(casearrays[i]);
        var id=casearrays[i];
        $("#checkcasetaskid [value="+id+"]").attr("selected",true);
        $("#checkcasetaskid [value="+id+"]").prop('checked', true)
    }
    console.log(JSON.stringify(gathttptaskparam()))
    // $("#taskcaseselectall>option").each(function (){
    //         for(var i=0;i<casearrays.length;i++){
    //             if(casearrays[i] == $(this).val()){
    //                 $(this).attr("selected",true);
    //             }
    //             else {
    //                 $(this).attr("selected",false);
    //             }
    //         }
    //     }
    // )
}


function gathttptaskparam(){
    var param={};
    param["taskname"]=$("#addtaskname").val();
    param["callnumber"]=$("#addcallnumber").val();
    param["runcycle"]=$("#addruncycle").val();
    param["projectid"]=$("#addprojectid").html();
    //var selectcases=$("#taskcaseselectall>option");
    var casestr="";
    $("[name='checkcasetaskname'] [type=checkbox]").each(function (){
        if($(this).is(':checked')){
            var value=$(this).val();
            casestr=casestr+value+","
        }
        }
    )

    // var casestr="";
    // for(var i=0;i<selectcases.length;i++){
    //     casestr=casestr+selectcases[i]+","
    // }
    if(casestr.length>0){
        casestr = casestr.substr(0, casestr.length - 1);
    }
    param["caseinfo"]=casestr;
    param["id"]=$("#addtaskid").html();
    return param;
}




function addupdatainfo(data){
    document.getElementById("taskmessage").style.display="";
    if(data.code != 0){
        var messages=data.message;
        document.getElementById("taskmessage").innerHTML=messages;
        setTimeout('displaynone(\'taskmessage\')',2000)
    }
    else{
        var messages="保存成功";
        document.getElementById("taskmessage").innerHTML=messages;
        setTimeout('refresh()',1000);
    }
}


function pausetask(taskid,status){
    $.get("/api/task/pause",{
        taskid:taskid,
        taskstatus:status
    },function (data){
        getinterinfomodeltype(data)
    })
}

function deltaskmodel(taskid){
    $("#delinterinfoModal").modal('show');
    $("#deltaskidmodel").html(taskid);
}

function deltaskinfohttp(){
    $.get("/api/task/del",{
        taskid:$("#deltaskidmodel").html()
    },function (data){
        getinterinfomodeltype(data)
    })
}